<template>
  <div class="cart-bottom-bar">
    <div class="check-content">
      <check-button class="check-btn" @click.native="checkClick" :is-checked='isCheckedAll'></check-button>
      <span>全选</span>
    </div>

    <div class="price">合计：{{ totalPrice }}</div>
    <div class="calculate">去计算：{{ checkedLength }}</div>
  </div>
</template>

<script>
import CheckButton from "../../../components/content/checkButton/CheckButton.vue";
export default {
  name: "CartBottomBar",
  data() {
    return {
      // 没有全选状态
      isCheck: false,
    };
  },
  components: {
    CheckButton,
  },
  computed: {
    totalPrice() {
      return this.$store.state.cartList
        .filter((item) => {
          return item.checked;
        })
        .reduce((total, item) => {
          return total + item.price * item.count;
        }, 0);
    },
    checkedLength() {
      return this.$store.state.cartList.filter((item) => {
        return item.checked
      }).length;
    },
    isCheckedAll(){
         return this.$store.state.cartList.length !== 0 && this.$store.state.cartList.every(item => item.checked)
    }
  },
  methods: {
    checkClick() {
      if (!this.isCheckedAll) {
        for (let item of this.$store.state.cartList) {
          item.checked = true;
        }
      }else{ 
        for (let item of this.$store.state.cartList) {
          item.checked = false;
        }}
    },
  },
};
</script>

<style scoped>
.cart-bottom-bar {
  height: 40px;
  background-color: #eee;
  position: relative;
  line-height: 40px;
  display: flex;
  justify-content: space-between;
}

.check-content {
  display: flex;
  align-items: center;
  padding-left: 10px;
}
.check-btn {
  width: 20px;
  height: 20px;
  line-height: 20px;
  margin-right: 10px;
}
.price {
  margin-left: 20px;
}
.calculate {
  width: 90px;
  padding-right: 6px;
  padding-left: 6px;
  background-color: pink;
  color: #fff;
  text-align: center;
}
/* .cart-bottom-bar{
        height: 40px;
        background-color: #eee;
        position: relative;
        line-height: 40px;
        display: flex;
        justify-content: space-between;
    }
    .check-content{
        display: flex;
        align-items: center;
        padding-left: 10px;
        
    }
    .check-btn{
        width: 20px;
        height: 20px;
        line-height: 20px;
        margin-right: 5px;
    }
    .price{
        margin-right: 20px;
        
    }
    .calculate{
        width: 90px;
        padding-right: 6px;
        padding-left: 6px;
        background-color: pink;
        color:#fff;
        text-align: center;
        
    } */
</style>